<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>模板</title>
  </head>
  <body>
    <!-- v-model用在表单身上 -->
    <div id="app">
      <form action="#">
        姓名(文本)：<input type="text" v-model="addform.msg" /> <br /><br />
        性别(单选按钮)：
        <input name="sex" type="radio" value="男" v-model="addform.sex" />男
        <input name="sex" type="radio" value="女" v-model="addform.sex" />女
        <br /><br />
        技能(多选框)：
        <input
          type="checkbox"
          name="skills"
          value="java"
          v-model="addform.like"
        />Java开发
        <input
          type="checkbox"
          name="skills"
          value="vue"
          v-model="addform.like"
        />Vue.js开发
        <input
          type="checkbox"
          name="skills"
          value="python"
          v-model="addform.like"
        />Python开发 <br /><br />
        城市(下拉框)：
        <select name="citys" v-model="addform.currentCity">
          <option v-for="item in city" :value="item.name">
            {{ item.name }}
          </option>
        </select>
        <br /><br />
        说明(多行文本)：<textarea
          cols="30"
          rows="5"
          v-model="addform.res"
        ></textarea>
        <br /><br />
        <button type="submit" @click.prevent.stop="add">提交</button>
      </form>

      <!-- v-model修饰符 number : 把字符串转成数字;trim:去除前后空格;lazy:把oninput改成onchange的效果，失去焦点内容有变化才触发 -->
      <input type="text" v-model.number.trim="num" />
      <input type="text" v-model.trim="str" />
      <input type="text" v-model.lazy="str" />
    </div>
  </body>
  <script src="../node_modules/vue/dist/vue.js"></script>
  <script>
    new Vue({
      el: "#app",
      data: {
        addform: {
          msg: "",
          sex: '',
          like: ["java", "vue"],
          currentCity: "广州",
          res: "",
        },

        num: 0,
        str: "",

        city: [
          {
            id: "1",
            name: "北京",
          },
          {
            id: "2",
            name: "上海",
          },
          {
            id: "3",
            name: "深圳",
          },
          {
            id: "4",
            name: "杭州",
          },
          {
            id: "5",
            name: "广州",
          },
        ],
      },

      methods: {
        add() {
          console.log(this.addform, 999);
        },
      },
    });
  </script>
</html>
